<template>
  <ele-modal
    :width="950"
    :visible="visible"
    :confirm-loading="loading"
    :title="'继续点数'"
    :body-style="{ paddingBottom: '18px' }"
    @update:visible="updateVisible"
    @ok="save"
    @cancel="cancel"
    :footer="null"
  >
    <a-form
      :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="23" :sm="23" :xs="23">
          <table cellpadding="0" cellspacing="0" class="recepit_table2">
            <tbody>
              <tr>
                <td>点数方式</td>
                <td class="tit">{{ detail.type_name || '' }}</td>
              </tr>
              <tr>
                <td>点数位置</td>
                <td class="tit">{{ detail.type_code_name || '' }}</td>
              </tr>
              <tr>
                <td>负责人</td>
                <td class="tit">{{ detail.charge_user_name || '' }}</td>
              </tr>
              <tr>
                <td>提交时间</td>
                <td class="tit">{{ detail.create_time || '' }}</td>
              </tr>
              <tr>
                <td>备注</td>
                <td class="tit">{{ detail.note || '' }}</td>
              </tr>
            </tbody>
          </table>
          <div class="fs-16 margin-y-30">货品点数</div>
          <vxe-table
            align="center"
            :data="tableData"
            :edit-config="{ trigger: 'click', mode: 'cell', showIcon: true }"
          >
            <vxe-column field="type_name" title="大类" />
            <vxe-column field="num" title="账面库存" />
            <vxe-column field="checked" title="点数" :edit-render="{}">
              <template #edit="{ row }">
                <vxe-input
                  v-model="row.checked"
                  type="number"
                  placeholder="请输入"
                />
              </template>
            </vxe-column>
          </vxe-table>
        </a-col>
        <a-col :md="23" :sm="23" :xs="23">
          <a-space class="margin-y-30 flex align-center justify-end">
            <a-button type="default" class="ele-btn-icon" @click="cancel()"
              ><span>取消</span></a-button
            >
            <a-button type="primary" class="ele-btn-icon" @click="save()"
              ><span>确定</span></a-button
            >
          </a-space>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  import {
    store_check_check,
    store_check_complete_check,
    store_check_delete
  } from '@/api/warehouse/store_check';

  // 表格列配置
  const useForm = Form.useForm;

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    dianshuId: [String, Number]
  });

  const emit = defineEmits(['done2', 'update:visible']);

  // 提交状态
  const loading = ref(false);
  const detail = ref({});
  const tableData = ref([]);
  const form = reactive({});

  onMounted(() => {
    store_check_check({ check_id: props.dianshuId })
      .then((res) => {
        detail.value = res.detail;
        res.list.forEach((item) => {
          item.checked = '';
        });
        tableData.value = res.list;
      })
      .catch((e) => {
        message.error(e);
      });
  });

  // 表单验证规则
  const rules = reactive({});

  const { validate, validateInfos } = useForm(form, rules);
  /* 保存 */
  const save = () => {
    validate()
      .then(() => {
        let params = {
          check_id: props.dianshuId,
          data: tableData.value
        };
        let isEmpty = params.data.every((item) => {
          return item.checked != '';
        });
        if (isEmpty) {
          store_check_complete_check(params)
            .then((res) => {
              message.success(res.msg);
              emit('done2');
            })
            .catch((e) => {
              message.error(e);
            });
        }
      })
      .catch(() => {});
  };
  /* 取消 */
  const cancel = () => {
    //emit('done2');
    store_check_delete({ id: props.dianshuId })
      .then((res) => {
        emit('done2');
        message.success(res.msg);
      })
      .catch((e) => {
        message.error(e);
      });
  };
  /* 更新visible */
  const updateVisible = (value) => {
	console.log('value===', value)
	/* if(!value){
		emit('done2');
	}
    emit('update:visible', value); */
	
  };
</script>
<style scoped></style>
